package com.ug_project.adapters

import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentPagerAdapter
import com.ug_project.objects.isNotNull
import com.ug_project.objects.isNull

/**
 * Created by Administrator on 2/19/2017.
 */

open class FragmentPagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm)
{
    private var _getItem: ((position: Int) -> Fragment)? = null
    private var _getCount: (() -> Int)? = null

    override fun getItem(position: Int): Fragment {
        var item = Fragment()
        _getItem isNull {throw Exception("پارامىتىر قۇرۇق بولۇپ قالسا بولمايدۇ") }
        _getItem isNotNull { item = _getItem!!(position) }
        return item
    }

    override fun getCount(): Int {
        var item = -1
        _getCount isNull {throw Exception("پارامىتىر قۇرۇق بولۇپ قالسا بولمايدۇ") }
        _getCount isNotNull { item = _getCount!!() }
        return item
    }
    open fun GetItem(getitem: (position: Int) -> Fragment)
    {
        _getItem = getitem
    }
    open fun GetCount(getcount: () -> Int)
    {
        _getCount = getcount;
    }
}

fun createFragmentPagerAdapter(fm: FragmentManager, constructor: com.ug_project.adapters.FragmentPagerAdapter.() -> Unit) : com.ug_project.adapters.FragmentPagerAdapter
{
    var item = com.ug_project.adapters.FragmentPagerAdapter(fm)
    item.constructor()
    return item
}